<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        var arr = [10,22,14,4];

        // 取最大值
        //1
        function maxOne(){
            var num = arr[0];
            for(let i=0; i<arr.length;i++){
            num = num> arr[i]?num:arr[i]
            }
        console.log("最大值为："+num)
        }
        maxOne();
        // 2
        console.log("最大值为："+Math.max(...arr));


        // 求和
        // 1
        function addOne(){
            var num = 0;
            for(let i=0; i<arr.length;i++){
            num += arr[i];
        }
        console.log("和为："+num)
        }
        addOne();
        console.log("和为："+arr.reduce((a,b)=>a+b));
    </script>
</body>
</html>